<template>
	<div class="allcontainer" v-loading="loading">
		<div id="components-form-demo-advanced-search">
			<!-- <div class="h2">积分申请管理（班主任）</div> -->
			<a-form class="ant-advanced-search-form home-form"  :form="form" @submit="handleSearch">
				<a-row >
					<a-col :span="8">
						<a-form-item label="我辅导的班级">
							<a-select :allowClear="true" v-decorator="['classID']" placeholder="全部"
								optionFilterProp="children" showSearch @change="ChangeClass">
								<a-select-option v-for="(item, index) in ClassData" :key="index" :value="item.ID">
									{{ item.Name }}/{{item.DepaerName}}
								</a-select-option>
							</a-select>
						</a-form-item>
						
					</a-col>
					<a-col :span="8">
						<a-form-item label="审批状态">
							<a-select :allowClear="true" v-decorator="['state']" placeholder="全部"
								optionFilterProp="children" showSearch >
								<a-select-option v-for="(item, index) in stateData" :key="index" :value="item.ID">
									{{ item.Name }}
								</a-select-option>
							</a-select>
						</a-form-item>
					</a-col>
					<a-col :span="8" style="margin-top:2px;">
						<a-button type="primary" html-type="submit" class="btn1" style="margin-left: 20px;">搜索</a-button>
						<a-button :style="{ marginLeft: '8px' }" @click="handleReset" class="btn2">重置</a-button>
						<!-- <a-button :style="{ marginLeft: '8px' }" type="primary" class="btn" v-if="classID!=''" @click="classSure" >批量确认</a-button>
						<a-button :style="{ marginLeft: '8px' }"  type="danger" class="btn" v-if="classID!=''" @click="deleteAllList">批量驳回</a-button> -->
					</a-col>
				</a-row>
			</a-form>
		</div>
		
		<div class="table">
			<!-- <el-table stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%"
				@expand-change="hangClick"> -->
				<el-table stripe ref="singleTable"  default-expand-all :data="data" @expand-change="hangClick" v-loading="loading"  @selection-change="handleSelectionChange" highlight-current-row style="width: 100%;">
					
				<el-table-column type="expand" prop="children">
					<template scope="scope">
						<el-table :data="scope.row.CreditApplyData">
							<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
							<el-table-column prop="No" label="编号" min-width="110" align="center"></el-table-column>
							<el-table-column prop="Title" label="名称" min-width="100"></el-table-column>
							<el-table-column prop="Name" label="状态/课程类型" min-width="240" align="center">
								<template slot-scope="scope">
									<a-tag :color="scope.row.State=='4'?'green':scope.row.State=='3'?'blue':'red'">{{ scope.row.StateName}}</a-tag>
									{{ scope.row.ActivityTypeName }}
								</template>
							</el-table-column>
							<el-table-column prop="ActivityTypePrizeName" label="奖项名称/类型" min-width="140"
								show-overflow-tooltip align="center">
								<template slot-scope="scope">
									{{ scope.row.ActivityTypePrizeName}} {{ scope.row.MemberTypeName}}
									</template>
							</el-table-column>
							<el-table-column prop="Score" label="分值" min-width="60" show-overflow-tooltip align="right">
							</el-table-column>
							<el-table-column prop="AddTime" label="申请时间" min-width="120" align="center"></el-table-column>
							<el-table-column  prop="FlowTypeName" label="审批节点" min-width="130" show-overflow-tooltip align="center">
							
							</el-table-column>
							<el-table-column prop="IsEnable" label="操作" min-width="60" fixed="right">
								<template slot-scope="scope">
									<!-- <a-tooltip placement="top">
										<template slot="title">修改</template>
										<i title="修改" class="iconfont icon-editor1" style="color: #1890FF;"
											@click="modifyList(scope.row, 'modify')"></i>
									</a-tooltip>
									<a-tooltip placement="top">
										<template slot="title">附件</template>
										<i title="附件" class="iconfont icon-fujian" style="color: #1890FF;"
											@click="seeList(scope.row, 'UserApplyEnclosure')"></i>
									</a-tooltip> -->
									<i title="撤回" v-if="scope.row.State=='3'&&scope.row.IsCanCancel" class="iconfont icon-assist-cancel" style="color: red;"
										@click="canceladmin(scope.row,4)"></i>
										<!-- <i title="删除"  class="iconfont icon-delete1" style="color: red;" @click="deletemember(scope.row)"></i> -->
								</template>
							</el-table-column>
						</el-table>
					</template>
				</el-table-column>
				<!-- <el-table-column type="selection" width="55" fixed="left"></el-table-column> -->
				<el-table-column type="index" label="序号" width="60" fixed="left" align="center"></el-table-column>
				<el-table-column prop="TotalScore" label="申请人" min-width="100" align="center">
					<template slot-scope="scope">
						<a-tag color="green">{{ scope.row.UserNo }}/{{ scope.row.UserName }}</a-tag>
					</template>
				</el-table-column>
				<el-table-column prop="ClassName" label="班级" min-width="100" align="center"></el-table-column>
				<el-table-column prop="DepartName" label="部门" min-width="100" align="center"></el-table-column>
				<el-table-column prop="TotalScore" label="总分" min-width="100" align="right"></el-table-column>
				<!-- <el-table-column prop="IsEnable" label="操作" min-width="100" fixed="right">
					<template slot-scope="scope">
						<i title="删除" v-if="!scope.row.IsManager" class="iconfont icon-delete1" style="color: red;" @click="deletemember(scope.row)"></i>
						<i title="详情" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-chakan" style="color: #1890FF;"
						 @click="detail(scope.row,1)"></i>
						<i title="修改权限" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-editor1" style="color: #1890FF;"
						 @click="detail(scope.row,2)"></i>
						<i title="设为管理员" v-if="!scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-guanliyuan1"
						 style="color: deeppink;" @click="detail(scope.row,3)"></i>
						<i title="取消管理员" v-if="scope.row.IsManager && ChairmanNo == UserInfo.UserNo" class="iconfont icon-assist-cancel"
						 style="color: red;" @click="canceladmin(scope.row,4)"></i>
					</template>
				</el-table-column> -->
			</el-table>
			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
				:current-page="pagination.currentPage" :page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"></el-pagination>
		</div>
		<add :ActivityTypePrizeTypeList="ActivityTypePrizeTypeList" :ActivityMemberTypeList="ActivityMemberTypeList"
			:ActivityTypeData="ActivityTypeData" :text="text" :DepartCodeList="DepartCodeList" :TypeIDList="TypeIDList"
			v-show="addIf" @closeFun="closeFun">
		</add>
		<!-- <detail :approvalType="4" :time="time" :text="text" :ID="ClubID" :linktype="linktype" v-show="showModal" @closeFun="closeFun(1)"></detail> -->
	</div>
</template>

<script>
	import add from './add';
	import Func from '@/utils/func';
	import Cache from '@/utils/cache';
	import {
		UserCreditApplyTeacherDoGetList,
		UserCreditApplyTeacherDoGetClassList,
		UserCreditApplyTeacherDoCancel,
		UserCreditApplyTeacherDoConfirm,
		UserCreditApplyTeacherDoBatchReturn,
		UserCreditApplyTeacherDoDelete
	} from '@/api/follow';
	// import detail from './detail';
	const data = [];
	export default {
		components: {
			add
			//	detail
		},
		data() {
			return {
				currentExpandRow:[],
				CreditSessionData: [],
				SemesterList: [],
			
				stateData: [{
					ID: '3',
					Name: "审核中"
				}, 
				{
					ID: '4',
					Name: "审核通过"
				}, 
				{
					ID: '6',
					Name: "审批驳回"
				} ],
				applyTypeData: [{
						ID: '1',
						Name: "参与申请"
					},
					{
						ID: '2',
						Name: "获奖申请"
					}
				],
				ActivityTypePrizeTypeList: [],
				ActivityMemberTypeList: [],
				ActivityTypeData: [],
				resourceC: [],
				ClassData: [],
				data,
				form: this.$form.createForm(this, {
					name: 'advanced_search'
				}),
				pagination: {
					currentPage: 1,
					pageSize: this.global.pageSize,
					pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
					showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
				},
				addIf: false,
				text: {},
				visible: false,
				confirmLoading: false,
				itemId: '',
				departmentList: [],
				worklist: [],
				loading: false,
				values: {},
				pages: {
					pageIndex: 1,
					pageSize: 20
				},
				tableHeight: parseFloat(window.innerHeight - 160),
				TypeIDList: [],
				DepartCodeList: [],
				ProjectIDList: [],
				ishaveid: true,
				selectList: {},
				showModal: false,
				UserInfo: Cache.get('myInfo'),
				ChairmanNo: this.$route.query.ChairmanNo,
				linktype: 1,
				ClubID: this.$route.query.ID,
				visible: false,
				deletelist: {},
				time: '',
				classID: "",
				multipleSelection:[]
			};
		},
		computed: {},
		created() {
			//this.getList();
			let clsid=localStorage.getItem("classID");
			if(clsid!=undefined){
				var that=this;
				that.classID=clsid;
				that.$nextTick(() => {
					that.form.setFieldsValue({
						classID:that.classID
					}, 300);
				})
				that.getList();
			}
			this.getOtherList()
		},
		mounted() {},
		methods: {
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			deleteAllList() {
				let that = this;
				if(this.classID!=''){
					this.$confirm({
						title: '提示',
						content: `当前操作会将当前班级申请全部驳回，是否继续操作？`,
						okText: '确认',
						cancelText: '取消',
						async onOk() {
							let data = {};
							data.classID=that.classID
							let res = await UserCreditApplyTeacherDoBatchReturn(data);
							if (res.data.code == 0) {
								that.getList();
							that.$message.success('成功'+res.data.Success+'条');
							} else {
								that.$message.success('失败'+res.data.Error+'条');
							}
						}
					});
				}else{
					that.$message.error('请选择班级');
				}
				// if (this.multipleSelection.length == 0) {
				// 	this.$message.error('请先选择要删除的数据！');
				// } else {
				// 	let that = this;
				// 	this.$confirm({
				// 		title: '提示',
				// 		content: '确定要删除选中的数据吗？',
				// 		okText: '确认',
				// 		cancelText: '取消',
				// 		async onOk() {
				// 			let list = that.multipleSelection;
				// 			for (let i = 0, len = list.length; i < len; i++) {
				// 				let data = {};
				// 				data.id = list[i].ID;
				// 				let res = await DeleteActivity(data);
				// 			}
				// 			that.getList();
				// 		}
				// 	});
				// }
			},
			classSure(){
				let that = this;
				if(this.classID!=''){
					this.$confirm({
						title: '提示',
						content: `当前操作会将当前班级申请确认，是否继续操作？`,
						okText: '确认',
						cancelText: '取消',
						async onOk() {
							let data = {};
							data.classID=that.classID
							let res = await UserCreditApplyTeacherDoConfirm(data);
							if (res.data.code == 0) {
								that.getList();
							that.$message.success('成功'+res.data.Success+'条');
							} else {
								that.$message.success('失败'+res.data.Error+'条');
							}
						}
					});
				}else{
					that.$message.error('请选择班级');
				}
				
			},
			seeList(text,name){
				this.$router.push({
					name: name,
					query: {
						ID: text.ID,
						Name: text.Name,
					}
				});
			},
			hangClick(e) {
				// this.resourceC=[];
				// this.resourceC = e.CreditApplyData;
			},
			ChangeClass(e) {
				this.classID = e;
				localStorage.setItem("classID",this.classID)
				this.getList()
			},
			async getOtherList() {
				let res = await UserCreditApplyTeacherDoGetClassList(data);
				this.ClassData = res.data.data;
			},
			// setadmin(text) {
			// 	let data={}
			// 	data.
			// 	let res = await DoAddUserClubMember(data)
			// },
			canceladmin(text) {
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定撤回该申请吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id=text.ID
						let res = await UserCreditApplyTeacherDoCancel(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			handleCancel(e) {
				this.visible = false;
				this.getList();
			},
			deletemember(text) {
				// this.visible = true
				// this.deletelist = text
				let that = this;
				this.$confirm({
					title: '提示',
					content: `您确定删除该申请吗？`,
					okText: '确认',
					cancelText: '取消',
					async onOk() {
						let data = {};
						data.id = text.ID;
						let res = await UserCreditApplyTeacherDoDelete(data);
						if (res.data.code == 0) {
							that.getList();
							that.$message.success(res.data.msg);
						} else {
							that.$message.error(res.data.msg);
						}
					}
				});
			},
			detail(text, type) {
				this.linktype = type;
				this.text = text;
				this.time = new Date();
				this.showModal = true;
			},
			handleChange(val) {
				this.currentRow = val;
				if (val.ID) {
					this.ishaveid = false;
					this.selectList = val;
				} else {
					this.ishaveid = true;
				}
			},
			handleSearch(e) {
				if (this.classID == '') {
					this.$message.error('请先选择班级');
					return
				}
				e.preventDefault();
				this.form.validateFields((error, values) => {
					this.pagination.currentPage = 1;
					this.values = values;
					this.getList();
				});
			},
			handleReset() {
				this.form.resetFields();
				this.values = {};
				this.getList();
			},
			handleSizeChange(val) {
				this.pagination.pageSize = val;
				this.getList();
			},
			handleCurrentChange(val) {
				this.pagination.currentPage = val;
				this.getList();
			},
			async getList() {
				this.loading = true;
				let data = {};
				if (this.values) {
					data = this.values;
				}
				data.classID = this.classID;
				data.pageIndex = this.pagination.currentPage;
				data.pageSize = this.pagination.pageSize;
				data.stateStr='3,4,6';
				let res = await UserCreditApplyTeacherDoGetList(data);
				this.loading = false;
				this.data = res.data.data;
				const pagination = {
					...this.pagination
				};
				pagination.total = res.data.pageInfo.totalItemCount;
				this.pagination = pagination;
			},
			addList() {
				this.text = {};
				this.addIf = !this.addIf;
			},
			modifyList(text) {
				text = Object.assign(text, {
					time: new Date()
				});
				this.addIf = !this.addIf;
				this.text = text;
			},
			closeFun(index) {
				this.addIf=false;
				this.showModal = false;
				this.getList();
			}
		}
	};
</script>

<style lang="less" scoped>
	/deep/.lableBox>div{
		width: 100px !important;
	}
</style>
